//
//  KDRightPageBtnModel.m
//  PublicSentimentMonitorSystem
//
//  Created by 魏强 on 15/6/15.
//  Copyright (c) 2015年 魏强. All rights reserved.
//

#import "KDRightPageBtnModel.h"
#define BEGIN_TIME @"beginTime"
#define END_TIME @"endTime"
@implementation KDRightPageBtnModel
- (void)setSign:(NSString *)sign
{
    _sign = sign;
    NSDateFormatter * formatter = [[NSDateFormatter alloc]init];
    //指定输出的格式   这里格式必须是和上面定义字符串的格式相同，否则输出空
    [formatter setDateFormat:@"yyyy-MM-dd"];
    if ([sign isEqualToString:@"1"]) {//全部
        self.startTime =nil;// @"1970-01-01";
        self.endTime = nil;//[formatter stringFromDate:[NSDate date]];
        self.beginDate = nil;
        self.endDate = nil;
    }else if ([sign isEqualToString:@"2"]){//今天
        NSDate * date = [NSDate date];
//        self.beginDate = date;
        self.endDate = date;
        self.startTime = [formatter stringFromDate:date];
        self.beginDate = [formatter dateFromString:self.startTime];
        self.endTime = [formatter stringFromDate:date];
    }else if ([sign isEqualToString:@"3"]){//一个星期
        NSDate *date = [NSDate date];
       
        NSDate *newdate = [[NSDate date] initWithTimeInterval:- (24 *60 * 60 * 6 )sinceDate: date];
        self.startTime = [formatter stringFromDate:newdate];
        self.endTime = [formatter stringFromDate:date];
        self.beginDate = newdate;
        self.endDate = date;
    }else if ([sign isEqualToString:@"4"]){//一个月
        NSCalendar *calendar = [[NSCalendar alloc] initWithCalendarIdentifier:NSCalendarIdentifierGregorian];
        
        NSDateComponents *adcomps = [[NSDateComponents alloc] init];
        [adcomps setMonth:-1];
        NSDate *newdate = [calendar dateByAddingComponents:adcomps toDate:[NSDate date] options:0];
        self.startTime = [formatter stringFromDate:newdate];
        self.endTime = [formatter stringFromDate:[NSDate date]];
        self.beginDate = newdate;
        self.endDate = [NSDate date];
    }else if ([sign isEqualToString:@"13"]){
        NSDate *begin = [[NSUserDefaults standardUserDefaults] objectForKey:BEGIN_TIME];
        NSDate *end = [[NSUserDefaults standardUserDefaults] objectForKey:END_TIME];
        self.startTime = [formatter stringFromDate:begin];
        self.endTime = [formatter stringFromDate:end];
        self.beginDate = begin;
        self.endDate = end;
    }
//    KDLog(@"%@",self.startTime);
}
@end
